<?php


namespace app\system\service;

class MyService
{
	public static function revise_password($options)
	{
		\think\Db::startTrans();
		try {
			$admin_info = \think\Db::name("system_admin")->where(["id" => $options["id"]])->find();
			$password = GeneratePassword($options["password"]);
			if ($password != $admin_info["password"]) {
				return ["code" => \app\system\model\Code::fail, "msg" => "原密码错误"];
			}
			$new_password = GeneratePassword($options["new_password"]);
			\think\Db::name("system_admin")->where(["id" => $options["id"]])->update(["password" => $new_password, "token" => md5(time())]);
			\think\Db::commit();
			return ["code" => \app\system\model\Code::success];
		} catch (\Exception $e) {
			\think\Db::rollback();
			return ["code" => \app\system\model\Code::error, "msg" => $e->getMessage()];
		}
	}
}